app.controller("z-salaryDetail-c",['$scope','$rootScope','$z-http','$sce','z-salaryDetail-s','z-dictionary-s','z-corporation-s','z-department-s','z-edit-menu-s','z-salaryRequest-s','$filter',
    function($scope,$rootScope,$zhttp,$sce,Service,DictionaryService,CorporationService,DepartmentService,MenuService,RequestService,$filter){
	$scope.viewModel = {};
	$scope.viewModel.perPage = "10";
	$scope.viewModel.rowCount = "1";
	$scope.viewModel.dataList=[];
    $scope.viewModel.historyDate = "";
	$scope.viewModel.historyMonths = [];
    $scope.viewModel.historyStartDate=null;
    $scope.viewModel.historyEndDate=null;
    $scope.viewModel.deleteDisabled=true;
    $scope.viewModel.descriptionMap = {};
	
	//查询页面名称
	MenuService.getMenuByUrl({url:'salaryDetail'},
	function(data){	
		$scope.viewModel.menuList=data;
	},function(error) {});

	$scope.selectModel = {};
	$scope.selectModel.data={};
    var yearList = [];
    var year = (new Date()).getFullYear();
    var month=(new Date()).getMonth()+1;
    for ( i=-3; i<4; i++ ) {
        yearList.push(year-i);
    }
    //$scope.selectModel.data.year=year;
    //$scope.selectModel.data.month=month;
    $scope.selectModel.data.yearList = yearList;
    
	$scope.viewModel.initData = function () {
		var nowData = new Date();
		nowData.setMonth(nowData.getMonth()-1);
        // 获取本月第一天
        $scope.viewModel.salaryYear = nowData.getFullYear();
        // 获取当前日期
        $scope.viewModel.salaryMonth = nowData.getMonth()+1;

        $scope.viewModel.employeeIsSeparated=null;
        $scope.viewModel.regionType=null;
        $scope.viewModel.employeeNo=null;
        $scope.viewModel.roleName=null;
        $scope.viewModel.departmentList=[];
        $scope.viewModel.corporationList=[];
        $scope.viewModel.employeeList=[];
        $scope.viewModel.level=null;
        $scope.viewModel.hashValue = null;
        $scope.viewModel.updateMap = {};
		//$scope.viewModel.isHistory = 0;
        $scope.viewModel.isPageTurning = 0;
    };
        
	var now = new Date();                    //当前日期     
	var nowMonth = now.getMonth();           //当前月     
	var nowYear=$filter('date')(now,'yyyy'); //当前年
	//获取当月开始日期
	var monthStartDate = $filter("date")(new Date(nowYear, nowMonth, 1), "yyyy/MM/dd");
	//获取当前日期
    var dayEndDate= $filter("date")(now, "yyyy/MM/dd");
	$scope.viewModel.startDate=new Date(monthStartDate);    //起止日期
	$scope.viewModel.endDate=new Date(dayEndDate);	  	  //终止日期

	//日期控件
	$scope.viewModel.dateOptions = {
		formatYear: 'yy',
		startingDay: 1,
		showWeeks:false
	};
	//日期控件
	$scope.viewModel.format = "yyyy/MM/dd";
	//日期启动开关
	$scope.viewModel.startDateOpened = false;
	$scope.viewModel.endDateOpened = false;
	//起止日期选择
	$scope.viewModel.startDateOpen = function($event) {
		$event.preventDefault();
		$event.stopPropagation();
        $scope.viewModel.endDateOpened = false;
		$scope.viewModel.startDateOpened = !$scope.viewModel.startDateOpened;
	};
	//起止日期选择
	$scope.viewModel.endDateOpen = function($event) {
		$event.preventDefault();
		$event.stopPropagation();
        $scope.viewModel.startDateOpened = false;
		$scope.viewModel.endDateOpened = !$scope.viewModel.endDateOpened;
	};
	
	//是否选中
	$scope.viewModel.historyDateSelected=function(value){
    	var valStartDate =$filter("date")(value.split('|||')[0], "yyyy/MM/dd");
    	var valEndDate = $filter("date")(value.split('|||')[1], "yyyy/MM/dd");
    	if($scope.viewModel.historyDate!=null || $scope.viewModel.historyDate!=""){
    		var historyStartDate=$filter("date")($scope.viewModel.historyDate.split('|||')[0], "yyyy/MM/dd");
    		var historyEndDate=$filter("date")($scope.viewModel.historyDate.split('|||')[1], "yyyy/MM/dd");
    		if(historyStartDate==valStartDate 
    				&& historyEndDate==valEndDate){
    			return true;
    		}
    	}
    	return false;
	};
	
	//删除保存明细
	$scope.viewModel.deleteDisabledType=function(){
		if($scope.viewModel.historyDate=="" 
			|| $scope.viewModel.historyDate==null){
			$scope.viewModel.deleteDisabled=true;
		}else{
			$scope.viewModel.deleteDisabled=false;
		}
	};
	
	//删除保存明细
	$scope.viewModel.deleteHistoryDate=function(){
        $rootScope.alertConfirm("确定是否删除明细！",
            function() {
        	 	$scope.viewModel.isLoading=true;
        	 	Service.deleteSalary({
        	 		historyStartDate:$scope.viewModel.historyStartDate,
	    			historyEndDate:$scope.viewModel.historyEndDate
	    		},
	    		function(data){
	    			$scope.viewModel.dataList=[];
	    			$scope.viewModel.historyDate="";
	    			$scope.viewModel.deleteDisabledType();
	    			$scope.viewModel.bindHistoryData();
	    			$rootScope.alertInfo("删除成功。");
	    			$scope.viewModel.historyStartDate=null;
	    			$scope.viewModel.historyEndDate=null;
	                $scope.viewModel.isLoading=false;
	    		},function(error) {
	    			$rootScope.alertError(error.fault.message);
	    			$scope.viewModel.isLoading=false;
	    		});
            });
	};
	

	$scope.viewModel.initData();
	//下拉多选框长度
	$scope.multiSelectMaxHeight=300;
	$scope.corporationList = [];
	$scope.viewModel.employeeLevelList = [];
	//加载信息
	$scope.viewModel.bindSelectRegionTypeData = function(){
		//查询公司
		CorporationService.getCorporationPermitList({
			//fromDate:$scope.viewModel.reportEndDate,
		},
		function(data){
			var site = [];  
	        $.each(data, function(index, values) {  
	            site.push({  
	                //label : "("+values.corporationCode+")"+values.corporationName,  
	            	label : values.corporationCode,  
	                value : values.corporationCode
	            });  
	        });
	        $scope.corporationList = site;
	        $('#sldCorporation').multiselect('dataprovider',site);
		},function(error) {

		});
	};

	$scope.viewModel.bindHistoryData = function () {
		$scope.viewModel.historyMonths = [];
		Service.getSalaryHistory({},
			function (data) { //success
				for(var i=0;i<data.length;i++){
					var historyMonths={};
//					historyMonths.lable= data[i].salaryYear+"年"+data[i].salaryMonth+"月";
					historyMonths.lable= "" + $filter("date")(data[i].startDate, "yyyy-MM-dd") + "至"+$filter("date")(data[i].endDate, "yyyy-MM-dd")
											+ " 上传时间：" + $filter("date")(data[i].updateTime, "yyyy-MM-dd HH:mm");
					historyMonths.value= data[i].startDate + "|||" + data[i].endDate + "|||" + data[i].salaryYear + "|||" + data[i].salaryMonth;
					$scope.viewModel.historyMonths.push(historyMonths);
				}
				/*$.each(data, function (index, val) {
					$scope.viewModel.historyMonths.push({
						//lable: "" + $filter("date")(val.startDate, "yyyy年MM月"),
						lable: val.salaryYear+"年"+val.salaryMonth+"月",
						value: val.startDate + "|||" + val.endDate + "|||" + val.salaryYear + "|||" + val.salaryMonth
					});
                });*/
            },
			function (data) {

        });
    };
	$scope.viewModel.bindSelectRegionTypeData();
	$scope.viewModel.bindHistoryData();

	/*******使用为下拉带勾选控件*********/
	//员工级别
	$('#sldlevel').multiselect({
		includeSelectAllOption: true,
		enableFiltering: true,
		delimiterText: '; ',
        maxHeight: $scope.multiSelectMaxHeight
    });
	//公司
	$('#sldCorporation').multiselect({
		includeSelectAllOption: true,
		enableFiltering: true,
		delimiterText: '; ',
        maxHeight: $scope.multiSelectMaxHeight
    });
	//公司选中事件
	$("#sldCorporation").change(function(){  
		var value=$(this).val();
	    var data={};
	    data.corporationCodeList=value;
	    data.fromDate = $scope.viewModel.reportEndDate;
	    if(value==null){
	    	var site = [];  
	    	$('#sldDepartmentName').multiselect('dataprovider',site);
	    	$scope.viewModel.departmentList=[];
	    }else{
	    	//查询部门
		    DepartmentService.getDepartmentListByCorporationCodeList(data,
			function(data){
		    	var site = [];  
		        $.each(data, function(index, values) {  
		            site.push({  
		                label : "("+values.departmentCode+")"+values.departmentName,  
		                value : values.departmentCode  
		            });  
		        });  
		        $('#sldDepartmentName').multiselect('dataprovider',site);
			},function(error) {
				
			});
	    }
    });  
	
	//部门
	$('#sldDepartmentName').multiselect({
		includeSelectAllOption: true,
		enableFiltering: true,
		delimiterText: '; ',
        maxHeight: $scope.multiSelectMaxHeight
    });

	$scope.viewModel.hashCode = function (str) {
        var hash = 0;
        if (str.length == 0) return hash;
        for (i = 0; i < str.length; i++) {
            char = str.charCodeAt(i);
            hash = ((hash<<5)-hash)+char;
            hash = hash & hash; // Convert to 32bit integer
        }
        return hash;
    }

	$scope.viewModel.makeParams = function() {
        $scope.viewModel.employeeList=[];
        if($scope.viewModel.employeeNo!=null){
            var employeeNoData = $scope.viewModel.employeeNo.split("\n");
            for(var i=0;i<employeeNoData.length;i++){
                $scope.viewModel.employeeList.push(employeeNoData[i]);
            }
        };
        var params =  {
            startDate: $scope.viewModel.startDate,
            endDate: $scope.viewModel.endDate,
            departmentList:$scope.viewModel.departmentList,
            corporationList:$scope.viewModel.corporationList,
            employeeList:$scope.viewModel.employeeList,
            employeeLevelList:$scope.viewModel.employeeLevelList,
            historyStartDate:$scope.viewModel.historyStartDate,
        	historyEndDate:$scope.viewModel.historyEndDate
			//isHistory: $scope.viewModel.isHistory,
		};
        /*if ( params.isHistory == '1' ) {
        	params.startDate = $scope.viewModel.historyDate.split('|||')[0];
            params.endDate = $scope.viewModel.historyDate.split('|||')[1];
            params.salaryYear = $scope.viewModel.historyDate.split('|||')[2];
            params.salaryMonth = $scope.viewModel.historyDate.split('|||')[3];
            params.employeeList = [];
            params.employeeLevelList = [];
		}*/
        var hashValueNew = $scope.viewModel.hashCode(JSON.stringify(params));
        if ( hashValueNew != $scope.viewModel.hashValue ) {
        	$scope.viewModel.updateMap = {};
            $scope.viewModel.hashValue = hashValueNew;
		}
        params.pageNo = $scope.viewModel.rowCount;
        params.pageCount = $scope.viewModel.perPage;
        params.isPageTurning = $scope.viewModel.isPageTurning;
		return params;
	};
	
	$scope.viewModel.editCols = ['beAttendanceDays','lateCount','lateMoney','leaveEarlyCount','leaveEarlyMoney','absentCount','retroactiveCount','overtimeNomal','overtimeWeekend','overtimeHoliday','restYearUsed','restTuneUsed','restThingUsed','restIllUsed','restMarryUsed','restBornUsed','restCheckUsed','restBornAttendUsed','restSuckleUsed','restDieUsed',];
	//加载数据
	$scope.viewModel.bindData = function(isReset){
		$scope.viewModel.isLoading=true;
		if ( isReset ) {
            $scope.viewModel.updateMap = {};
		}
		//获取基本信息
		Service.getSalaryList($scope.viewModel.makeParams(),
		function(data){
			var list = data.salaryBeanList.map(function (value) {
                $scope.viewModel.editCols.map(function(col) {
                	var cor = col + 'Cor',
						edit = col + 'Edit';
                    // process *Cor
                    if ( value[cor] == null ) {
                        value[cor] = value[col] ;//|| "";
                    }
                    // process *Edit 
                    var _key = value.isTemp==1 ? value.employeeNo : value.employeeNo;
                    if ($scope.viewModel.updateMap.hasOwnProperty(_key)) {
                        value[edit] = $scope.viewModel.updateMap[_key][cor];
                    } else {
                        value[edit] = value[cor];
                    }
				});
				return value;
            });
			$scope.viewModel.dataList = list;
			for(var i=0;i<$scope.viewModel.dataList.length;i++){
				var employeeNo=$scope.viewModel.descriptionMap[$scope.viewModel.dataList[i].employeeNo];
	        	if(employeeNo!=null){
	        		$scope.viewModel.dataList[i].description=employeeNo.descriptionCor;
	        	}
			}
			$scope.viewModel.totalData = data.pageTotal;
			$scope.viewModel.popInit();
			$scope.viewModel.isLoading=false;
		},function(error) {
			$scope.viewModel.isLoading=false;
			$rootScope.alertError(error.fault.message);
		});
	};

	$scope.viewModel.changePage = function () {
		var updateMap = $scope.viewModel.updateMap || {};
		var salaryBeanList = [];
				var updateMapList=[];
				for ( skey in updateMap ) {
					var obj = updateMap[skey];
					// obj.salaryId = skey;
		            salaryBeanList.push(obj);
		            updateMapList.push(obj);
				}
				
		var params = {};
			params.salaryBeanList=salaryBeanList;
	        
	        for(var j=0;j<params.salaryBeanList.length;j++){
	    		var data=$scope.viewModel.descriptionMap[params.salaryBeanList[j].employeeNo];
	        	if(data!=null){
	        		params.salaryBeanList[j].descriptionCor=data.descriptionCor;
	        	}
	        }
	        
	        for(var i=0;i<updateMapList.length;i++){
	        	var dataMap=null;
	        	for(var j=0;j<$scope.viewModel.dataList.length;j++){
	        		if($scope.viewModel.dataList[j].employeeNo==updateMapList[i].employeeNo){
	        			var dataMap=$scope.viewModel.dataList[j];
	        		}
	        	}
	        	if(dataMap!=null){
	        		if(((updateMapList[i].beAttendanceDaysCor!=null && updateMapList[i].beAttendanceDaysCor!="")
		        			&& updateMapList[i].beAttendanceDaysCor!=dataMap.beAttendanceDays)
		        			|| ((updateMapList[i].lateCountCor!=null && updateMapList[i].lateCountCor!="") 
		        					&& updateMapList[i].lateCountCor!=dataMap.lateCount) 
		        			|| ((updateMapList[i].lateMoneyCor!=null && updateMapList[i].lateMoneyCor!="") 
		        					&& updateMapList[i].lateMoneyCor!=dataMap.lateMoney) 
		        			|| ((updateMapList[i].leaveEarlyCountCor!=null && updateMapList[i].leaveEarlyCountCor!="") 
		        					&& updateMapList[i].leaveEarlyCountCor!=dataMap.leaveEarlyCount) 
		        			|| ((updateMapList[i].leaveEarlyMoneyCor!=null && updateMapList[i].leaveEarlyMoneyCor!="")
		        					&& updateMapList[i].leaveEarlyMoneyCor!=dataMap.leaveEarlyMoney) 
		        			|| ((updateMapList[i].absentCountCor!=null && updateMapList[i].absentCountCor!="") 
		        					&& updateMapList[i].absentCountCor!=dataMap.absentCount) 
		        			|| ((updateMapList[i].retroactiveCountCor!=null && updateMapList[i].retroactiveCountCor!="") 
		        					&& updateMapList[i].retroactiveCountCor!=dataMap.retroactiveCount)
		        			|| ((updateMapList[i].overtimeNomalCor!=null && updateMapList[i].overtimeNomalCor!="")
		        					&& updateMapList[i].overtimeNomalCor!=dataMap.overtimeNomal) 
		        			|| ((updateMapList[i].overtimeWeekendCor!=null && updateMapList[i].overtimeWeekendCor!="") 
		        					&& updateMapList[i].overtimeWeekendCor!=dataMap.overtimeWeekend) 
		        			|| ((updateMapList[i].overtimeHolidayCor!=null && updateMapList[i].overtimeHolidayCor!="")
		        					&& updateMapList[i].overtimeHolidayCor!=dataMap.overtimeHoliday)
		        			|| ((updateMapList[i].restYearUsedCor!=null && updateMapList[i].restYearUsedCor!="")
		        					&& updateMapList[i].restYearUsedCor!=dataMap.restYearUsed) 
		        			|| ((updateMapList[i].restTuneUsedCor!=null && updateMapList[i].restTuneUsedCor!="")
		        					&& updateMapList[i].restTuneUsedCor!=dataMap.restTuneUsed) 
		        			|| ((updateMapList[i].restThingUsedCor!=null && updateMapList[i].restThingUsedCor!="")
		        					&& updateMapList[i].restThingUsedCor!=dataMap.restThingUsed)
		        			|| ((updateMapList[i].restIllUsedCor!=null && updateMapList[i].restIllUsedCor!="")
		        					&& updateMapList[i].restIllUsedCor!=dataMap.restIllUsed) 
		        			|| ((updateMapList[i].restMarryUsedCor!=null && updateMapList[i].restMarryUsedCor!="")
		        					&& updateMapList[i].restMarryUsedCor!=dataMap.restMarryUsed) 
		        			|| ((updateMapList[i].restBornUsedCor!=null && updateMapList[i].restBornUsedCor!="") 
		        					&& updateMapList[i].restBornUsedCor!=dataMap.restBornUsed)
		        			|| ((updateMapList[i].restCheckUsedCor!=null && updateMapList[i].restCheckUsedCor!="")
		        					&& updateMapList[i].restCheckUsedCor!=dataMap.restCheckUsed)
		        			|| ((updateMapList[i].restBornAttendUsedCor!=null && updateMapList[i].restBornAttendUsedCor!="")
		        					&& updateMapList[i].restBornAttendUsedCor!=dataMap.restBornAttendUsed)
		        			|| ((updateMapList[i].restSuckleUsedCor!=null && updateMapList[i].restSuckleUsedCor!="") 
		        					&& updateMapList[i].restSuckleUsedCor!=dataMap.restSuckleUsed)
		        			|| ((updateMapList[i].restDieUsedCor!=null && updateMapList[i].restDieUsedCor!="")
		        					&& updateMapList[i].restDieUsedCor!=dataMap.restDieUsed)){
		        		if(updateMapList[i].descriptionCor==null
		            			|| updateMapList[i].descriptionCor==""){
		            	    var strList=[];
		            	    strList.push("员工:"+updateMapList[i].chineseName+" ("+updateMapList[i].employeeNo+")");
		            	    strList.push("未填写更改备注，请填写后保存！");
		                	$rootScope.alertWarning(strList);
		                	$scope.viewModel.isLoading=false;
		                	return;
		            	}
		        	}
	        	}
	        }
		
		$scope.viewModel.isPageTurning = '1';
        $scope.viewModel.bindData(false);
    };
    
	$scope.viewModel.search = function() {
        $scope.viewModel.isPageTurning = '0';
        $scope.viewModel.isHistory = '0';
        $scope.viewModel.bindData(true);
	};
	
	$scope.viewModel.changeHistory = function () {
        $scope.viewModel.isHistory = '1';
        $scope.viewModel.historyStartDate=null;
        $scope.viewModel.historyEndDate=null;
        $scope.viewModel.isPageTurning = '0';
        if ($scope.viewModel.historyDate == '' ) {
            $scope.viewModel.isHistory = '0';
            $scope.viewModel.dataList = [];
		} else {
			/*var nowData = new Date();
			nowData.setMonth(nowData.getMonth()-1);
	        // 获取本月第一天
	        $scope.viewModel.salaryYear = nowData.getFullYear();
	        // 获取当前日期
	        $scope.viewModel.salaryMonth = nowData.getMonth()+1;

	        $scope.viewModel.departmentList=[];
	        $scope.viewModel.corporationList=[];
	        $scope.viewModel.employeeList=[];*/
	        
	        //设置开始日期和结束日期
	        $scope.viewModel.startDate=$scope.viewModel.historyDate.split('|||')[0];
	        $scope.viewModel.endDate=$scope.viewModel.historyDate.split('|||')[1];
	        //设置保存明细开始日期和结束日期
	        $scope.viewModel.historyStartDate=$scope.viewModel.historyDate.split('|||')[0];
	        $scope.viewModel.historyEndDate=$scope.viewModel.historyDate.split('|||')[1];
        	$scope.viewModel.bindData(true);
		}
        $scope.viewModel.deleteDisabledType();
    };


	// 导出
	$scope.viewModel.exportData= function() {
		$scope.viewModel.isLoading=true;
        var employeeList=[];
        if($scope.selectModel.data.employeeNo!=null){
            var employeeNoData = $scope.selectModel.data.employeeNo.split("\n");
            for(var i=0;i<employeeNoData.length;i++){
                employeeList.push(employeeNoData[i]);
            }
        };
		var params = {
            salaryYear: $scope.selectModel.data.year,
            salaryMonth: $scope.selectModel.data.month,
            corporationList: $scope.selectModel.data.corporations,
            departmentList: $scope.selectModel.data.departments,
            employeeList: employeeList
		};
		Service.getExportSalary(params,
			function(data){
				$scope.viewModel.isLoading=false;
                $scope.viewModel.unLoadPop();
				//alert("导出被注释了。");
				window.location.href = data;
			},function(error) {
				$rootScope.alertError(error.fault.message);
				$scope.viewModel.isLoading=false;
		});
	};

	$scope.viewModel.clear = function (obj, target) {
		if ( obj && obj.hasOwnProperty(target)) {
			obj[target] = false;
		}
    };
	$scope.viewModel.popInit = function() {
        $scope.selectModel = {};
        $scope.selectModel.data = {};
        var nowData = new Date();
        nowData.setMonth(nowData.getMonth()-1);
        var params =  {
        		corporationList:  $scope.viewModel.corporationList
    		};
        if ( $scope.viewModel.historyDate == '' || $scope.viewModel.historyDate == null) {
        	RequestService.getYearMonth(params, function (data) {
        		$scope.selectModel.data.year = data.salaryYear;
        		$scope.selectModel.data.month = data.salaryMonth;
        	}, function (data) {
        		
        	});
        } else {
        	$scope.selectModel.data.year = $scope.viewModel.historyDate.split('|||')[2];
    		$scope.selectModel.data.month = $scope.viewModel.historyDate.split('|||')[3];
        }
		$scope.selectModel.data.historyDate="";
        var yearList = [];
        var year = (new Date()).getFullYear();
        for ( i=-3; i<4; i++ ) {
            yearList.push(year-i);
        }
        $scope.selectModel.data.yearList = yearList;
        $scope.selectModel.data.corporations = [];
        $scope.selectModel.data.description = null;
        $scope.viewModel.clear($scope.selectPopForm.description, '$dirty');
        $scope.viewModel.clear($scope.selectPopForm.year, '$dirty');
        $scope.viewModel.clear($scope.selectPopForm.month, '$dirty');
	};

	// 导入
	$scope.viewModel.importData = function () {
		alert("等待确认。。");
	};

	$scope.viewModel.unLoadPop = function() {
        $scope.selectModel.showSubmit = false;
        $scope.selectModel.showSave = false;
        $scope.selectModel.showExport = false;
	};

	// 提交确认
	$scope.viewModel.saveSnsPop = function () {
		$scope.viewModel.popInit();
		$scope.selectModel.title = "工资报表提交申请";
		$scope.selectModel.type = 1;
		$scope.selectModel.showSubmit = true;
		setTimeout(function(){
			   //部门
		        $('#popMultiple').multiselect({
		            includeSelectAllOption: true,
		            enableFiltering: true,
		            delimiterText: '; ',
		            maxHeight: $scope.multiSelectMaxHeight
		        });
		        $('#popMultiple').multiselect('dataprovider',$scope.corporationList);
		 }, 100);
	};

	$scope.viewModel.saveDataPop = function () {
		var dataList = $scope.viewModel.dataList || [];
        if ( dataList.length <= 0 ) {
            $rootScope.alertWarning("没有要保存的数据。");
            $scope.viewModel.isLoading=false;
            return ;
        }
//		$scope.viewModel.popInit();
//		$scope.selectModel.title = "工资报表保存";
		$scope.selectModel.type = 0;
//		$scope.selectModel.showSave = true;
//		$scope.selectModel.isSubmit = true;
		$scope.viewModel.savePop();
	};

    $scope.viewModel.exportDataPop2 = function () {
    	$scope.viewModel.isLoading=true;
        var dataList = $scope.viewModel.dataList || [];
        if ( dataList.length <= 0 ) {
            $rootScope.alertWarning("没有要导出的数据。");
            $scope.viewModel.isLoading=false;
            return ;
        }
        var params = angular.copy($scope.viewModel.makeParams());
        params.historyStartDate= $scope.viewModel.historyStartDate;
        params.historyEndDate=$scope.viewModel.historyEndDate;
        delete params.isPageTurning;
        delete params.pageCount;
        delete params.pageNo;
        Service.getExportSalary(params,
            function(data){
                $scope.viewModel.isLoading=false;
//                alert("导出被注释了。");
                 window.location.href = data;
            },function(error) {
                $rootScope.alertError(error.fault.message);
                $scope.viewModel.isLoading=false;
            });
    };

	$scope.viewModel.exportDataPop = function () {
        $scope.viewModel.popInit();
        $scope.selectModel.title = "工资报表导出";
        $scope.selectModel.type = 2;
        $scope.selectModel.showExport = true;
        $scope.selectModel.isSubmit = true;

        setTimeout(function(){
            //公司
            $('#popMultiple3').multiselect({
                includeSelectAllOption: true,
                enableFiltering: true,
                delimiterText: '; ',
                maxHeight: $scope.multiSelectMaxHeight
            });
            $('#popMultiple3').multiselect('dataprovider',$scope.corporationList);
            //部门
            $('#popDepartmentName').multiselect({
                includeSelectAllOption: true,
                enableFiltering: true,
                delimiterText: '; ',
                maxHeight: $scope.multiSelectMaxHeight
            });
            //公司选中事件
            $("#popMultiple3").change(function(){
                var value=$(this).val();
                var data={};
                data.corporationCodeList=value;
                data.fromDate = $scope.viewModel.reportEndDate;
                if(value!=null){
                    //查询部门
                    DepartmentService.getDepartmentListByCorporationCodeList(data,
                        function(data){
                            var site = [];
                            $.each(data, function(index, values) {
                                site.push({
                                    label : "("+values.departmentCode+")"+values.departmentName,
                                    value : values.departmentCode
                                });
                            });
                            $('#popDepartmentName').multiselect('dataprovider',site);
                        },function(error) {

                        });
                } else {
                    var site = [];
                    $('#popDepartmentName').multiselect('dataprovider',site);
                    $scope.selectModel.data.departments=[];
				}
            });
        }, 100);
    };

	$scope.viewModel.popValidate = function () {
		var isValidate = false;
        if (!$scope.selectPopForm.month.$valid
            || !$scope.selectPopForm.year.$valid) {
            if($scope.selectModel.data.month ==null
                || $scope.selectModel.data.month ==""){
                $scope.selectPopForm.month.$dirty=true;
                $scope.selectPopForm.month.$invalid=true;
                isValidate = true;
            }
            if($scope.selectModel.data.year ==null
                || $scope.selectModel.data.year ==""){
                $scope.selectPopForm.year.$dirty=true;
                $scope.selectPopForm.year.$invalid=true;
                isValidate = true;
            }
        }
        return isValidate;
    };
	$scope.viewModel.savePop = function () {
		if ( $scope.selectModel.type == 0 ) {
			// 保存
			$scope.viewModel.saveData();
		} else if ( $scope.selectModel.type == 1 ) {
			// 申请并提交
			$scope.viewModel.saveSns();
		} else if ( $scope.selectModel.type == 2 ) {
			// 导出
			$scope.viewModel.exportData();
		}
	};
	// 按月份保存并提交申请
	$scope.viewModel.saveSns = function () {
        if ($scope.viewModel.popValidate() ) {
            return;
		}
        var updateMap = $scope.viewModel.updateMap || {};
        
        if($scope.selectModel.data.historyDate==""
        	|| $scope.selectModel.data.historyDate==null){
            $rootScope.alertWarning("请选择明细！");
            return ;
        }
        if($scope.selectModel.data.year=="" || $scope.selectModel.data.year==null){
            $rootScope.alertWarning("请选择年份！");
            return ;
        }
        if($scope.selectModel.data.month=="" || $scope.selectModel.data.month==null){
            $rootScope.alertWarning("请选择月份！");
            return ;
        }
        $scope.viewModel.isLoading=true;
/*        var salaryBeanList = [];
        for ( skey in updateMap ) {
            var obj = updateMap[skey];
            // obj.salaryId = skey;
            salaryBeanList.push(obj);
        }
        if ( salaryBeanList.length == 0 ) {
            var data0 = dataList[0];
            data0 = JSON.parse(JSON.stringify(data0));
            $scope.viewModel.editCols.map(function(col){
                delete data0[col+'Edit'];
            });
            salaryBeanList.push(data0);
        } */
        var params = {
            salaryYear: $scope.selectModel.data.year,
            salaryMonth: $scope.selectModel.data.month,
            corporationList: $scope.selectModel.data.corporations,
            description: $scope.selectModel.data.description,
            //salaryBeanList: salaryBeanList,
            historyStartDate:$scope.selectModel.data.historyDate.split('|||')[0],
            historyEndDate:$scope.selectModel.data.historyDate.split('|||')[1]
        };
        RequestService.saveSalaryRequestList(params,function (data) {
            $scope.viewModel.isLoading=false;
            $scope.viewModel.unLoadPop();
            $rootScope.alertInfo("申请提交成功。");
           // $scope.viewModel.bindHistoryData();
            $scope.viewModel.unLoadPop();
        },function (error) {
            $rootScope.alertError(error.fault.message);
            $scope.viewModel.isLoading=false;
        })
    };

	// 保存
	$scope.viewModel.saveData = function() {
        var updateMap = $scope.viewModel.updateMap || {};
        var dataList = $scope.viewModel.dataList || [];
/*        if($scope.selectModel.data.year==null || $scope.selectModel.data.year==""){
        	$rootScope.alertWarning("请选择年份。");
            $scope.viewModel.isLoading=false;
 			return ;
        }
        if($scope.selectModel.data.month==null || $scope.selectModel.data.month==""){
        	$rootScope.alertWarning("请选择月份。");
            $scope.viewModel.isLoading=false;
 			return ;
        }*/
		if (Object.keys(updateMap).length <= 0 && dataList.length <= 0 ) {
            $rootScope.alertWarning("没有要保存的数据。");
            $scope.viewModel.isLoading=false;
			return ;
		}
        $scope.viewModel.isLoading=true;
		var salaryBeanList = [];
		var updateMapList=[];
		for ( skey in updateMap ) {
			var obj = updateMap[skey];
			// obj.salaryId = skey;
            salaryBeanList.push(obj);
            updateMapList.push(obj);
		}
		if ( salaryBeanList.length == 0 ) {
			var data0 = dataList[0];
			data0 = JSON.parse(JSON.stringify(data0));
            $scope.viewModel.editCols.map(function(col){
                delete data0[col+'Edit'];
            });
            salaryBeanList.push(data0);
		}

		/*alert(JSON.stringify(salaryBeanList));
		$scope.viewModel.isLoading=false;
    	return;*/
		/*var historyDate=$scope.viewModel.historyDate;
		if(historyDate=="" || historyDate==null){
			historyDate=0;
		}else{
			historyDate=1;
		}*/
		var params = angular.copy($scope.viewModel.makeParams());
		params.salaryBeanList=salaryBeanList;
		/*params.salaryMonth=$scope.selectModel.data.month;
		params.salaryYear=$scope.selectModel.data.year;*/
        params.historyStartDate= $scope.viewModel.historyStartDate;
        params.historyEndDate=$scope.viewModel.historyEndDate;
        delete params.isPageTurning;
        delete params.pageCount;
        delete params.pageNo;
        
        for(var j=0;j<params.salaryBeanList.length;j++){
    		var data=$scope.viewModel.descriptionMap[params.salaryBeanList[j].employeeNo];
        	if(data!=null){
        		params.salaryBeanList[j].descriptionCor=data.descriptionCor;
        	}
        }
        
        for(var i=0;i<updateMapList.length;i++){
        	var dataMap=null;
        	for(var j=0;j<$scope.viewModel.dataList.length;j++){
        		if($scope.viewModel.dataList[j].employeeNo==updateMapList[i].employeeNo){
        			var dataMap=$scope.viewModel.dataList[j];
        		}
        	}
        	if(((updateMapList[i].beAttendanceDaysCor!=null && updateMapList[i].beAttendanceDaysCor!="")
        			&& updateMapList[i].beAttendanceDaysCor!=dataMap.beAttendanceDays)
        			|| ((updateMapList[i].lateCountCor!=null && updateMapList[i].lateCountCor!="") 
		        					&& updateMapList[i].lateCountCor!=dataMap.lateCount) 
		        	|| ((updateMapList[i].lateMoneyCor!=null && updateMapList[i].lateMoneyCor!="") 
		        					&& updateMapList[i].lateMoneyCor!=dataMap.lateMoney) 
        			|| ((updateMapList[i].leaveEarlyCountCor!=null && updateMapList[i].leaveEarlyCountCor!="") 
        					&& updateMapList[i].leaveEarlyCountCor!=dataMap.leaveEarlyCount) 
        			|| ((updateMapList[i].leaveEarlyMoneyCor!=null && updateMapList[i].leaveEarlyMoneyCor!="")
        					&& updateMapList[i].leaveEarlyMoneyCor!=dataMap.leaveEarlyMoney) 
        			|| ((updateMapList[i].absentCountCor!=null && updateMapList[i].absentCountCor!="") 
        					&& updateMapList[i].absentCountCor!=dataMap.absentCount) 
        			|| ((updateMapList[i].retroactiveCountCor!=null && updateMapList[i].retroactiveCountCor!="") 
        					&& updateMapList[i].retroactiveCountCor!=dataMap.retroactiveCount)
        			|| ((updateMapList[i].overtimeNomalCor!=null && updateMapList[i].overtimeNomalCor!="")
        					&& updateMapList[i].overtimeNomalCor!=dataMap.overtimeNomal) 
        			|| ((updateMapList[i].overtimeWeekendCor!=null && updateMapList[i].overtimeWeekendCor!="") 
        					&& updateMapList[i].overtimeWeekendCor!=dataMap.overtimeWeekend) 
        			|| ((updateMapList[i].overtimeHolidayCor!=null && updateMapList[i].overtimeHolidayCor!="")
        					&& updateMapList[i].overtimeHolidayCor!=dataMap.overtimeHoliday)
        			|| ((updateMapList[i].restYearUsedCor!=null && updateMapList[i].restYearUsedCor!="")
        					&& updateMapList[i].restYearUsedCor!=dataMap.restYearUsed) 
        			|| ((updateMapList[i].restTuneUsedCor!=null && updateMapList[i].restTuneUsedCor!="")
        					&& updateMapList[i].restTuneUsedCor!=dataMap.restTuneUsed) 
        			|| ((updateMapList[i].restThingUsedCor!=null && updateMapList[i].restThingUsedCor!="")
        					&& updateMapList[i].restThingUsedCor!=dataMap.restThingUsed)
        			|| ((updateMapList[i].restIllUsedCor!=null && updateMapList[i].restIllUsedCor!="")
        					&& updateMapList[i].restIllUsedCor!=dataMap.restIllUsed) 
        			|| ((updateMapList[i].restMarryUsedCor!=null && updateMapList[i].restMarryUsedCor!="")
        					&& updateMapList[i].restMarryUsedCor!=dataMap.restMarryUsed) 
        			|| ((updateMapList[i].restBornUsedCor!=null && updateMapList[i].restBornUsedCor!="") 
        					&& updateMapList[i].restBornUsedCor!=dataMap.restBornUsed)
        			|| ((updateMapList[i].restCheckUsedCor!=null && updateMapList[i].restCheckUsedCor!="")
        					&& updateMapList[i].restCheckUsedCor!=dataMap.restCheckUsed)
        			|| ((updateMapList[i].restBornAttendUsedCor!=null && updateMapList[i].restBornAttendUsedCor!="")
        					&& updateMapList[i].restBornAttendUsedCor!=dataMap.restBornAttendUsed)
        			|| ((updateMapList[i].restSuckleUsedCor!=null && updateMapList[i].restSuckleUsedCor!="") 
        					&& updateMapList[i].restSuckleUsedCor!=dataMap.restSuckleUsed)
        			|| ((updateMapList[i].restDieUsedCor!=null && updateMapList[i].restDieUsedCor!="")
        					&& updateMapList[i].restDieUsedCor!=dataMap.restDieUsed)){
        		if(updateMapList[i].descriptionCor==null
            			|| updateMapList[i].descriptionCor==""){
            	    var strList=[];
            	    strList.push("员工:"+updateMapList[i].chineseName+" ("+updateMapList[i].employeeNo+")");
            	    strList.push("未填写更改备注，请填写后保存！");
                	$rootScope.alertWarning(strList);
                	$scope.viewModel.isLoading=false;
                	return;
            	}
        	}
        }
        
        Service.updateSalaryList(params,
			function(data){
                $scope.viewModel.bindData(true);
                $scope.viewModel.unLoadPop();
                $scope.viewModel.bindHistoryData();
                $rootScope.alertInfo("保存成功。");
                $scope.viewModel.isLoading=false;
			},
			function(error){
                $rootScope.alertWarning(error['fault']['message']);
                $scope.viewModel.isLoading=false;
			});
	};

	$scope.viewModel.ulShow = false;

	$scope.viewModel.clearNum = function(obj, attr){
		obj[attr] = obj[attr].replace(/\D/g,"");
	};
	$scope.viewModel.changNumber = function(obj) {
        var changed = $scope.viewModel.editCols.filter(function(col){
        	var edit = col + "Edit",
				cor  = col + "Cor";
        	return obj[edit] != obj[cor];
		});
        var _key = obj.isTemp==1 ? obj.employeeNo : obj.employeeNo;
        if ( changed.length > 0 ) {
            $scope.viewModel.updateMap[_key] = {
				startDate: obj.startDate,
				endDate: obj.endDate,
				employeeNo:obj.employeeNo,
				chineseName:obj.chineseName,
                employeeNoSubmit: obj.employeeNoSubmit,
                requestState: obj.requestState,
                salaryTempId: obj.salaryTempId,
                salaryId: obj.salaryId,
                isTemp: obj.isTemp,
                deptmentNameOne: obj.deptmentNameOne,
                descriptionCor:null
            }
            var $obj = $scope.viewModel.updateMap[_key];
            $scope.viewModel.editCols.map(function(col){
                $obj[col+'Cor'] = obj[col+'Edit'];
            });
		} else if ($scope.viewModel.updateMap.hasOwnProperty(_key)) {
            delete $scope.viewModel.updateMap[_key];
		}
		for(var j=0;j<$scope.viewModel.dataList.length;j++){
			if(obj.employeeNo==$scope.viewModel.dataList[j].employeeNo){
				$scope.viewModel.descriptionMap[obj.employeeNo] = {
					descriptionCor: obj.description
		        };
				break;
			}
		}
    };
    
    //备注更改事件
    $scope.viewModel.changeDesc=function(salaryDetail){
		 $scope.viewModel.descriptionMap[salaryDetail.employeeNo] = {
			 descriptionCor: salaryDetail.description
	     };
    };
    
    //是否可用输入框
    $scope.viewModel.disabledDesc=function(salaryDetail){
    	var data=$scope.viewModel.updateMap[salaryDetail.employeeNo];
    	if(data!=null){
    		return false;
    	}else{
    		return true;
    	}
    };
    
	//表格按钮点击事件
	$scope.viewModel.salaryButton = function(e){
		e.stopPropagation();
		if($scope.viewModel.ulShow == false){
			$(".salaryUl").show();
			$scope.viewModel.ulShow = true;
		}else{
			$(".salaryUl").hide();
			$scope.viewModel.ulShow = false;
		}
	};
	$(document).click(function(){
		$(".salaryUl").hide();
		$scope.viewModel.ulShow = false;
	});
	$(".salaryUl").click(function(event){
		 event.stopPropagation();
	});
	// 定义表格下拉数据
	$scope.viewModel.checkList = [{dicId:"1",dicName:"一级架构"},
	                              {dicId:"2",dicName:"二级架构"},
	                              {dicId:"3",dicName:"三级架构"},
	                              {dicId:"4",dicName:"四级架构"},
	                              {dicId:"5",dicName:"工号"},
	                              {dicId:"6",dicName:"中文名"},
	                              {dicId:"7",dicName:"英文名"},
	                              {dicId:"8",dicName:"岗位"},
	                              {dicId:"9",dicName:"入职日期"},
	                              {dicId:"10",dicName:"离职日期"},
	                              {dicId:"11",dicName:"应出勤天数"},
	                              {dicId:"13",dicName:"迟到次数"},
	                              {dicId:"14",dicName:"迟到扣款"},
	                              {dicId:"15",dicName:"早退次数"},
	                              {dicId:"16",dicName:"早退扣款"},
	                              {dicId:"17",dicName:"旷工次数"},
	                              {dicId:"18",dicName:"补签次数"},
	                              {dicId:"19",dicName:"平日加班"},
	                              {dicId:"20",dicName:"双休加班"},
	                              {dicId:"21",dicName:"节日加班"},
	                              {dicId:"22",dicName:"年假"},
	                              {dicId:"23",dicName:"调休"},
	                              {dicId:"24",dicName:"事假"},
	                              {dicId:"25",dicName:"病假"},
	                              {dicId:"26",dicName:"婚假"},
	                              {dicId:"27",dicName:"产假"},
	                              {dicId:"28",dicName:"产检"},
	                              {dicId:"29",dicName:"陪护假"},
	                              {dicId:"30",dicName:"哺乳假"},
	                              {dicId:"31",dicName:"丧假"},              
	                              {dicId:"32",dicName:"备注"}];
	// 设置初始值
	$scope.viewModel.checkbox1 = true;
	$scope.viewModel.checkbox2 = true;
	$scope.viewModel.checkbox3 = true;
	$scope.viewModel.checkbox4 = true;
	$scope.viewModel.checkbox5 = true;
	$scope.viewModel.checkbox6 = true;
	$scope.viewModel.checkbox7 = true;
	$scope.viewModel.checkbox8 = true;
	$scope.viewModel.checkbox9 = true;
	$scope.viewModel.checkbox10 = true;
	$scope.viewModel.checkbox11 = true;
//	$scope.viewModel.checkbox12 = true;
	$scope.viewModel.checkbox13 = true;
	$scope.viewModel.checkbox14 = true;
	$scope.viewModel.checkbox15 = true;
    $scope.viewModel.checkbox16 = true;
	$scope.viewModel.checkbox17 = true;
	$scope.viewModel.checkbox18 = true;
	$scope.viewModel.checkbox19 = true;
	$scope.viewModel.checkbox20= true;
	$scope.viewModel.checkbox21 = true;
    $scope.viewModel.checkbox22 = true;
	$scope.viewModel.checkbox23 = true;
	$scope.viewModel.checkbox24 = true;
	$scope.viewModel.checkbox25 = true;
	$scope.viewModel.checkbox26= true;
	$scope.viewModel.checkbox27 = true;
	$scope.viewModel.checkbox28 = true;
	$scope.viewModel.checkbox29 = true;
	$scope.viewModel.checkbox30 = true;
	$scope.viewModel.checkbox31= true;
	$scope.viewModel.checkbox32 = true;

	var x=document.getElementById('salary-table').rows[0].cells;
	$scope.viewModel.checkbox = function(type){
		if(type == 1){
			if($scope.viewModel.checkbox1 == true){
				x[0].colSpan = x[0].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox1 == true || $scope.viewModel.checkbox2 == true || $scope.viewModel.checkbox3 == true || $scope.viewModel.checkbox4 == true || $scope.viewModel.checkbox5 == true || $scope.viewModel.checkbox6 == true || $scope.viewModel.checkbox7 == true || $scope.viewModel.checkbox8 == true || $scope.viewModel.checkbox9 == true || $scope.viewModel.checkbox10 == true){
					x[0].colSpan = x[0].colSpan * 1 + 1;
				}else{
					x[0].colSpan = x[0].colSpan;
					$("#salary-table thead tr th:eq(0)").show();
				}
			}
			$scope.viewModel.checkbox1 = !$scope.viewModel.checkbox1;
			if($scope.viewModel.checkbox1 == false && $scope.viewModel.checkbox2 == false && $scope.viewModel.checkbox3 == false && $scope.viewModel.checkbox4 == false && $scope.viewModel.checkbox5 == false && $scope.viewModel.checkbox6 == false && $scope.viewModel.checkbox7 == false && $scope.viewModel.checkbox8 == false && $scope.viewModel.checkbox9 == false && $scope.viewModel.checkbox10 == false){
				$("#salary-table thead tr th:eq(0)").hide();
			}else{
				$("#salary-table thead tr th:eq(0)").show();
			}
		}
		if(type == 2){
			if($scope.viewModel.checkbox2 == true){
				x[0].colSpan = x[0].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox1 == true || $scope.viewModel.checkbox2 == true || $scope.viewModel.checkbox3 == true || $scope.viewModel.checkbox4 == true || $scope.viewModel.checkbox5 == true || $scope.viewModel.checkbox6 == true || $scope.viewModel.checkbox7 == true || $scope.viewModel.checkbox8 == true || $scope.viewModel.checkbox9 == true || $scope.viewModel.checkbox10 == true){
					x[0].colSpan = x[0].colSpan * 1 + 1;
				}else{
					x[0].colSpan = x[0].colSpan;
					$("#salary-table thead tr th:eq(0)").show();
				}
			}
			$scope.viewModel.checkbox2 = !$scope.viewModel.checkbox2;
			if($scope.viewModel.checkbox1 == false && $scope.viewModel.checkbox2 == false && $scope.viewModel.checkbox3 == false && $scope.viewModel.checkbox4 == false && $scope.viewModel.checkbox5 == false && $scope.viewModel.checkbox6 == false && $scope.viewModel.checkbox7 == false && $scope.viewModel.checkbox8 == false && $scope.viewModel.checkbox9 == false && $scope.viewModel.checkbox10 == false){
				$("#salary-table thead tr th:eq(0)").hide();
			}else{
				$("#salary-table thead tr th:eq(0)").show();
			}
		}
		if(type == 3){
			if($scope.viewModel.checkbox3 == true){
				x[0].colSpan = x[0].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox1 == true || $scope.viewModel.checkbox2 == true || $scope.viewModel.checkbox3 == true || $scope.viewModel.checkbox4 == true || $scope.viewModel.checkbox5 == true || $scope.viewModel.checkbox6 == true || $scope.viewModel.checkbox7 == true || $scope.viewModel.checkbox8 == true || $scope.viewModel.checkbox9 == true || $scope.viewModel.checkbox10 == true){
					x[0].colSpan = x[0].colSpan * 1 + 1;
				}else{
					x[0].colSpan = x[0].colSpan;
					$("#salary-table thead tr th:eq(0)").show();
				}
			}
			$scope.viewModel.checkbox3 = !$scope.viewModel.checkbox3;
			if($scope.viewModel.checkbox1 == false && $scope.viewModel.checkbox2 == false && $scope.viewModel.checkbox3 == false && $scope.viewModel.checkbox4 == false && $scope.viewModel.checkbox5 == false && $scope.viewModel.checkbox6 == false && $scope.viewModel.checkbox7 == false && $scope.viewModel.checkbox8 == false && $scope.viewModel.checkbox9 == false && $scope.viewModel.checkbox10 == false){
				$("#salary-table thead tr th:eq(0)").hide();
			}else{
				$("#salary-table thead tr th:eq(0)").show();
			}
		}
		if(type == 4){
			if($scope.viewModel.checkbox4 == true){
				x[0].colSpan = x[0].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox1 == true || $scope.viewModel.checkbox2 == true || $scope.viewModel.checkbox3 == true || $scope.viewModel.checkbox4 == true || $scope.viewModel.checkbox5 == true || $scope.viewModel.checkbox6 == true || $scope.viewModel.checkbox7 == true || $scope.viewModel.checkbox8 == true || $scope.viewModel.checkbox9 == true || $scope.viewModel.checkbox10 == true){
					x[0].colSpan = x[0].colSpan * 1 + 1;
				}else{
					x[0].colSpan = x[0].colSpan;
					$("#salary-table thead tr th:eq(0)").show();
				}
			}
			$scope.viewModel.checkbox4 = !$scope.viewModel.checkbox4;
			if($scope.viewModel.checkbox1 == false && $scope.viewModel.checkbox2 == false && $scope.viewModel.checkbox3 == false && $scope.viewModel.checkbox4 == false && $scope.viewModel.checkbox5 == false && $scope.viewModel.checkbox6 == false && $scope.viewModel.checkbox7 == false && $scope.viewModel.checkbox8 == false && $scope.viewModel.checkbox9 == false && $scope.viewModel.checkbox10 == false){
				$("#salary-table thead tr th:eq(0)").hide();
			}else{
				$("#salary-table thead tr th:eq(0)").show();
			}
		}
		if(type == 5){
			if($scope.viewModel.checkbox5 == true){
				x[0].colSpan = x[0].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox1 == true || $scope.viewModel.checkbox2 == true || $scope.viewModel.checkbox3 == true || $scope.viewModel.checkbox4 == true || $scope.viewModel.checkbox5 == true || $scope.viewModel.checkbox6 == true || $scope.viewModel.checkbox7 == true || $scope.viewModel.checkbox8 == true || $scope.viewModel.checkbox9 == true || $scope.viewModel.checkbox10 == true){
					x[0].colSpan = x[0].colSpan * 1 + 1;
				}else{
					x[0].colSpan = x[0].colSpan;
					$("#salary-table thead tr th:eq(0)").show();
				}
			}
			$scope.viewModel.checkbox5 = !$scope.viewModel.checkbox5;
			if($scope.viewModel.checkbox1 == false && $scope.viewModel.checkbox2 == false && $scope.viewModel.checkbox3 == false && $scope.viewModel.checkbox4 == false && $scope.viewModel.checkbox5 == false && $scope.viewModel.checkbox6 == false && $scope.viewModel.checkbox7 == false && $scope.viewModel.checkbox8 == false && $scope.viewModel.checkbox9 == false && $scope.viewModel.checkbox10 == false){
				$("#salary-table thead tr th:eq(0)").hide();
			}else{
				$("#salary-table thead tr th:eq(0)").show();
			}
		}
		if(type == 6){
			if($scope.viewModel.checkbox6 == true){
				x[0].colSpan = x[0].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox1 == true || $scope.viewModel.checkbox2 == true || $scope.viewModel.checkbox3 == true || $scope.viewModel.checkbox4 == true || $scope.viewModel.checkbox5 == true || $scope.viewModel.checkbox6 == true || $scope.viewModel.checkbox7 == true || $scope.viewModel.checkbox8 == true || $scope.viewModel.checkbox9 == true || $scope.viewModel.checkbox10 == true){
					x[0].colSpan = x[0].colSpan * 1 + 1;
				}else{
					x[0].colSpan = x[0].colSpan;
					$("#salary-table thead tr th:eq(0)").show();
				}
			}
			$scope.viewModel.checkbox6 = !$scope.viewModel.checkbox6;
			if($scope.viewModel.checkbox1 == false && $scope.viewModel.checkbox2 == false && $scope.viewModel.checkbox3 == false && $scope.viewModel.checkbox4 == false && $scope.viewModel.checkbox5 == false && $scope.viewModel.checkbox6 == false && $scope.viewModel.checkbox7 == false && $scope.viewModel.checkbox8 == false && $scope.viewModel.checkbox9 == false && $scope.viewModel.checkbox10 == false){
				$("#salary-table thead tr th:eq(0)").hide();
			}else{
				$("#salary-table thead tr th:eq(0)").show();
			}
		}
		if(type == 7){
			if($scope.viewModel.checkbox7 == true){
				x[0].colSpan = x[0].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox1 == true || $scope.viewModel.checkbox2 == true || $scope.viewModel.checkbox3 == true || $scope.viewModel.checkbox4 == true || $scope.viewModel.checkbox5 == true || $scope.viewModel.checkbox6 == true || $scope.viewModel.checkbox7 == true || $scope.viewModel.checkbox8 == true || $scope.viewModel.checkbox9 == true || $scope.viewModel.checkbox10 == true){
					x[0].colSpan = x[0].colSpan * 1 + 1;
				}else{
					x[0].colSpan = x[0].colSpan;
					$("#salary-table thead tr th:eq(0)").show();
				}
			}
			$scope.viewModel.checkbox7 = !$scope.viewModel.checkbox7;
			if($scope.viewModel.checkbox1 == false && $scope.viewModel.checkbox2 == false && $scope.viewModel.checkbox3 == false && $scope.viewModel.checkbox4 == false && $scope.viewModel.checkbox5 == false && $scope.viewModel.checkbox6 == false && $scope.viewModel.checkbox7 == false && $scope.viewModel.checkbox8 == false && $scope.viewModel.checkbox9 == false && $scope.viewModel.checkbox10 == false){
				$("#salary-table thead tr th:eq(0)").hide();
			}else{
				$("#salary-table thead tr th:eq(0)").show();
			}
		}
		if(type == 8){
			if($scope.viewModel.checkbox8 == true){
				x[0].colSpan = x[0].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox1 == true || $scope.viewModel.checkbox2 == true || $scope.viewModel.checkbox3 == true || $scope.viewModel.checkbox4 == true || $scope.viewModel.checkbox5 == true || $scope.viewModel.checkbox6 == true || $scope.viewModel.checkbox7 == true || $scope.viewModel.checkbox8 == true || $scope.viewModel.checkbox9 == true || $scope.viewModel.checkbox10 == true){
					x[0].colSpan = x[0].colSpan * 1 + 1;
				}else{
					x[0].colSpan = x[0].colSpan;
					$("#salary-table thead tr th:eq(0)").show();
				}
			}
			$scope.viewModel.checkbox8 = !$scope.viewModel.checkbox8;
			if($scope.viewModel.checkbox1 == false && $scope.viewModel.checkbox2 == false && $scope.viewModel.checkbox3 == false && $scope.viewModel.checkbox4 == false && $scope.viewModel.checkbox5 == false && $scope.viewModel.checkbox6 == false && $scope.viewModel.checkbox7 == false && $scope.viewModel.checkbox8 == false && $scope.viewModel.checkbox9 == false && $scope.viewModel.checkbox10 == false){
				$("#salary-table thead tr th:eq(0)").hide();
			}else{
				$("#salary-table thead tr th:eq(0)").show();
			}
		}
		if(type == 9){
			if($scope.viewModel.checkbox9 == true){
				x[0].colSpan = x[0].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox1 == true || $scope.viewModel.checkbox2 == true || $scope.viewModel.checkbox3 == true || $scope.viewModel.checkbox4 == true || $scope.viewModel.checkbox5 == true || $scope.viewModel.checkbox6 == true || $scope.viewModel.checkbox7 == true || $scope.viewModel.checkbox8 == true || $scope.viewModel.checkbox9 == true || $scope.viewModel.checkbox10 == true){
					x[0].colSpan = x[0].colSpan * 1 + 1;
				}else{
					x[0].colSpan = x[0].colSpan;
					$("#salary-table thead tr th:eq(0)").show();
				}
			}
			$scope.viewModel.checkbox9 = !$scope.viewModel.checkbox9;
			if($scope.viewModel.checkbox1 == false && $scope.viewModel.checkbox2 == false && $scope.viewModel.checkbox3 == false && $scope.viewModel.checkbox4 == false && $scope.viewModel.checkbox5 == false && $scope.viewModel.checkbox6 == false && $scope.viewModel.checkbox7 == false && $scope.viewModel.checkbox8 == false && $scope.viewModel.checkbox9 == false && $scope.viewModel.checkbox10 == false){
				$("#salary-table thead tr th:eq(0)").hide();
			}else{
				$("#salary-table thead tr th:eq(0)").show();
			}
		}
		if(type == 10){
			if($scope.viewModel.checkbox10 == true){
				x[0].colSpan = x[0].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox1 == true || $scope.viewModel.checkbox2 == true || $scope.viewModel.checkbox3 == true || $scope.viewModel.checkbox4 == true || $scope.viewModel.checkbox5 == true || $scope.viewModel.checkbox6 == true || $scope.viewModel.checkbox7 == true || $scope.viewModel.checkbox8 == true || $scope.viewModel.checkbox9 == true || $scope.viewModel.checkbox10 == true){
					x[0].colSpan = x[0].colSpan * 1 + 1;
				}else{
					x[0].colSpan = x[0].colSpan;
					$("#salary-table thead tr th:eq(0)").show();
				}
			}
			$scope.viewModel.checkbox10 = !$scope.viewModel.checkbox10;
			if($scope.viewModel.checkbox1 == false && $scope.viewModel.checkbox2 == false && $scope.viewModel.checkbox3 == false && $scope.viewModel.checkbox4 == false && $scope.viewModel.checkbox5 == false && $scope.viewModel.checkbox6 == false && $scope.viewModel.checkbox7 == false && $scope.viewModel.checkbox8 == false && $scope.viewModel.checkbox9 == false && $scope.viewModel.checkbox10 == false){
				$("#salary-table thead tr th:eq(0)").hide();
			}else{
				$("#salary-table thead tr th:eq(0)").show();
			}
		}
		if(type == 11){
			if($scope.viewModel.checkbox11 == true){
				x[1].colSpan = x[1].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox11 == true){
					x[1].colSpan = x[1].colSpan * 1 + 1;
				}else{
					x[1].colSpan = x[1].colSpan;
					$("#salary-table thead tr th:eq(1)").show();
				}
			}
			$scope.viewModel.checkbox11 = !$scope.viewModel.checkbox11;
			if($scope.viewModel.checkbox11 == false){
				$("#salary-table thead tr th:eq(1)").hide();
			}else{
				$("#salary-table thead tr th:eq(1)").show();
			}
		}
//		if(type == 12){
//			if($scope.viewModel.checkbox12 == true){
//				x[1].colSpan = x[1].colSpan - 1;
//			}else{
//				if($scope.viewModel.checkbox11 == true || $scope.viewModel.checkbox12 == true){
//					x[1].colSpan = x[1].colSpan * 1 + 1;
//				}else{
//					x[1].colSpan = x[1].colSpan;
//					$("#report-table thead tr th:eq(1)").show();
//				}
//			}
//			$scope.viewModel.checkbox12 = !$scope.viewModel.checkbox12;
//			if($scope.viewModel.checkbox11 == false && $scope.viewModel.checkbox12 == false){
//				$("#report-table thead tr th:eq(1)").hide();
//			}else{
//				$("#report-table thead tr th:eq(1)").show();
//			}
//		}
		if(type == 13){
			if($scope.viewModel.checkbox13 == true){
				x[2].colSpan = x[2].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox13 == true || $scope.viewModel.checkbox14 == true ||  $scope.viewModel.checkbox15== true || $scope.viewModel.checkbox16 == true || $scope.viewModel.checkbox17 == true || $scope.viewModel.checkbox18 == true){
					x[2].colSpan = x[2].colSpan * 1 + 1;
				}else{
					x[2].colSpan = x[2].colSpan;
					$("#salary-table thead tr th:eq(2)").show();
				}
			}
			$scope.viewModel.checkbox13 = !$scope.viewModel.checkbox13;
			if($scope.viewModel.checkbox13 == false && $scope.viewModel.checkbox14 == false && $scope.viewModel.checkbox15 == false && $scope.viewModel.checkbox16 == false && $scope.viewModel.checkbox17 == false && $scope.viewModel.checkbox18 == false){
				$("#salary-table thead tr th:eq(2)").hide();
			}else{
				$("#salary-table thead tr th:eq(2)").show();
			}
		}
		if(type == 14){
			if($scope.viewModel.checkbox14 == true){
				x[2].colSpan = x[2].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox13 == true || $scope.viewModel.checkbox14 == true || $scope.viewModel.checkbox15 == true || $scope.viewModel.checkbox16 == true || $scope.viewModel.checkbox17 == true || $scope.viewModel.checkbox18 == true){
					x[2].colSpan = x[2].colSpan * 1 + 1;
				}else{
					x[2].colSpan = x[2].colSpan;
					$("#salary-table thead tr th:eq(2)").show();
				}
			}
			$scope.viewModel.checkbox14 = !$scope.viewModel.checkbox14;
			if($scope.viewModel.checkbox13 == false && $scope.viewModel.checkbox14 == false && $scope.viewModel.checkbox15 == false && $scope.viewModel.checkbox16 == false && $scope.viewModel.checkbox17 == false && $scope.viewModel.checkbox18 == false){
				$("#salary-table thead tr th:eq(2)").hide();
			}else{
				$("#salary-table thead tr th:eq(2)").show();
			}
		}
		if(type == 15){
			if($scope.viewModel.checkbox15 == true){
				x[2].colSpan = x[2].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox13 == true || $scope.viewModel.checkbox14 == true ||  $scope.viewModel.checkbox15 == true || $scope.viewModel.checkbox16 == true || $scope.viewModel.checkbox17 == true || $scope.viewModel.checkbox18 == true){
					x[2].colSpan = x[2].colSpan * 1 + 1;
				}else{
					x[2].colSpan = x[2].colSpan;
					$("#salary-table thead tr th:eq(2)").show();
				}
			}
			$scope.viewModel.checkbox15 = !$scope.viewModel.checkbox15;
			if($scope.viewModel.checkbox13 == false && $scope.viewModel.checkbox15 == false && $scope.viewModel.checkbox17 == false && $scope.viewModel.checkbox171 == false){
				$("#salary-table thead tr th:eq(2)").hide();
			}else{
				$("#salary-table thead tr th:eq(2)").show();
			}
		}
		if(type == 16){
			if($scope.viewModel.checkbox16 == true){
				x[2].colSpan = x[2].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox13 == true || $scope.viewModel.checkbox14 == true || $scope.viewModel.checkbox15 == true || $scope.viewModel.checkbox16 == true || $scope.viewModel.checkbox17 == true || $scope.viewModel.checkbox18 == true){
					x[2].colSpan = x[2].colSpan * 1 + 1;
				}else{
					x[2].colSpan = x[2].colSpan;
					$("#salary-table thead tr th:eq(2)").show();
				}
			}
			$scope.viewModel.checkbox16 = !$scope.viewModel.checkbox16;
			if($scope.viewModel.checkbox13 == false && $scope.viewModel.checkbox14 == false && $scope.viewModel.checkbox15 == false && $scope.viewModel.checkbox16 == false && $scope.viewModel.checkbox17 == false && $scope.viewModel.checkbox18== false){
				$("#rsalary-table thead tr th:eq(2)").hide();
			}else{
				$("#salary-table thead tr th:eq(2)").show();
			}
		}
		if(type == 17){
			if($scope.viewModel.checkbox17 == true){
				x[2].colSpan = x[2].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox13 == true || $scope.viewModel.checkbox14 == true ||  $scope.viewModel.checkbox15 == true || $scope.viewModel.checkbox16 == true || $scope.viewModel.checkbox17 == true || $scope.viewModel.checkbox18 == true){
					x[2].colSpan = x[2].colSpan * 1 + 1;
				}else{
					x[2].colSpan = x[2].colSpan;
					$("#salary-table thead tr th:eq(2)").show();
				}
			}
			$scope.viewModel.checkbox17 = !$scope.viewModel.checkbox17;
			if($scope.viewModel.checkbox13 == false && $scope.viewModel.checkbox14 == false && $scope.viewModel.checkbox15 == false && $scope.viewModel.checkbox16 == false  && $scope.viewModel.checkbox17 == false  && $scope.viewModel.checkbox18 == false){
				$("#salary-table thead tr th:eq(2)").hide();
			}else{
				$("#salary-table thead tr th:eq(2)").show();
			}
		}
		if(type == 18){
			if($scope.viewModel.checkbox18 == true){
				x[2].colSpan = x[2].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox13 == true || $scope.viewModel.checkbox14 == true ||  $scope.viewModel.checkbox15 == true || $scope.viewModel.checkbox16 == true || $scope.viewModel.checkbox17 == true || $scope.viewModel.checkbox18 == true){
					x[2].colSpan = x[2].colSpan * 1 + 1;
				}else{
					x[2].colSpan = x[2].colSpan;
					$("#salary-table thead tr th:eq(2)").show();
				}
			}
			$scope.viewModel.checkbox18 = !$scope.viewModel.checkbox18;
			if($scope.viewModel.checkbox13 == false && $scope.viewModel.checkbox14 == false && $scope.viewModel.checkbox15 == false && $scope.viewModel.checkbox16 == false  && $scope.viewModel.checkbox17 == false  && $scope.viewModel.checkbox18 == false){
				$("#salary-table thead tr th:eq(2)").hide();
			}else{
				$("#salary-table thead tr th:eq(2)").show();
			}
		}
		if(type == 19){
			if($scope.viewModel.checkbox19== true){
				x[3].colSpan = x[3].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox19 == true ||  $scope.viewModel.checkbox20 == true ||  $scope.viewModel.checkbox21 == true){
					x[3].colSpan = x[3].colSpan * 1 + 1;
				}else{
					x[3].colSpan = x[3].colSpan;
					$("#salary-table thead tr th:eq(3)").show();
				}
			}
			$scope.viewModel.checkbox19 = !$scope.viewModel.checkbox19;
			if($scope.viewModel.checkbox19 == false && $scope.viewModel.checkbox20 == false && $scope.viewModel.checkbox21 == false){
				$("#salary-table thead tr th:eq(3)").hide();
			}else{
				$("#salary-table thead tr th:eq(3)").show();
			}
		}
		if(type == 20){
			if($scope.viewModel.checkbox20 == true){
				x[3].colSpan = x[3].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox19 == true || $scope.viewModel.checkbox20 == true || $scope.viewModel.checkbox21 == true){
					x[3].colSpan = x[3].colSpan * 1 + 1;
				}else{
					x[3].colSpan = x[3].colSpan;
					$("#salary-table thead tr th:eq(3)").show();
				}
			}
			$scope.viewModel.checkbox20 = !$scope.viewModel.checkbox20;
			if($scope.viewModel.checkbox19 == false && $scope.viewModel.checkbox20 == false && $scope.viewModel.checkbox21 == false){
				$("#salary-table thead tr th:eq(3)").hide();
			}else{
				$("#salary-table thead tr th:eq(3)").show();
			}
		}
		if(type == 21){
			if($scope.viewModel.checkbox21 == true){
				x[3].colSpan = x[3].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox19 == true || $scope.viewModel.checkbox20 == true || $scope.viewModel.checkbox21== true){
					x[3].colSpan = x[3].colSpan * 1 + 1;
				}else{
					x[3].colSpan = x[3].colSpan;
					$("#salary-table thead tr th:eq(3)").show();
				}
			}
			$scope.viewModel.checkbox21 = !$scope.viewModel.checkbox21;
			if($scope.viewModel.checkbox19 == false && $scope.viewModel.checkbox20 == false && $scope.viewModel.checkbox21 == false){
				$("#salary-table thead tr th:eq(3)").hide();
			}else{
				$("#salary-table thead tr th:eq(3)").show();
			}
		}    
	

		if(type == 22){
			if($scope.viewModel.checkbox22 == true){
				x[4].colSpan = x[4].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox22 == true || $scope.viewModel.checkbox23 == true || $scope.viewModel.checkbox24 == true || $scope.viewModel.checkbox25 == true || $scope.viewModel.checkbox26 == true || $scope.viewModel.checkbox27 == true || $scope.viewModel.checkbox28 == true || $scope.viewModel.checkbox29 == true || $scope.viewModel.checkbox30 == true || $scope.viewModel.checkbox31 == true){
					x[4].colSpan = x[4].colSpan * 1 + 1;
				}else{
					x[4].colSpan = x[4].colSpan;
					$("#salary-table thead tr th:eq(4)").show();
				}
			}
			$scope.viewModel.checkbox22 = !$scope.viewModel.checkbox22;
			if($scope.viewModel.checkbox22 == false && $scope.viewModel.checkbox23 == false && $scope.viewModel.checkbox24 == false && $scope.viewModel.checkbox25== false && $scope.viewModel.checkbox26 == false && $scope.viewModel.checkbox27 == false && $scope.viewModel.checkbox28 == false && $scope.viewModel.checkbox29 == false && $scope.viewModel.checkbox30 == false && $scope.viewModel.checkbox31 == false){
				$("#salary-table thead tr th:eq(4)").hide();
			}else{
				$("#salary-table thead tr th:eq(4)").show();
			}
		}
		
		if(type == 23){
			if($scope.viewModel.checkbox23 == true){
				x[4].colSpan = x[4].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox22 == true || $scope.viewModel.checkbox23 == true || $scope.viewModel.checkbox24 == true || $scope.viewModel.checkbox25 == true || $scope.viewModel.checkbox26 == true || $scope.viewModel.checkbox27 == true || $scope.viewModel.checkbox28 == true || $scope.viewModel.checkbox29 == true || $scope.viewModel.checkbox30 == true || $scope.viewModel.checkbox31 == true){
					x[4].colSpan = x[4].colSpan * 1 + 1;
				}else{
					x[4].colSpan = x[4].colSpan;
					$("#salary-table thead tr th:eq(4)").show();
				}
			}
			$scope.viewModel.checkbox23 = !$scope.viewModel.checkbox23;
			if($scope.viewModel.checkbox22 == false && $scope.viewModel.checkbox23 == false && $scope.viewModel.checkbox24 == false && $scope.viewModel.checkbox25== false && $scope.viewModel.checkbox26 == false && $scope.viewModel.checkbox27 == false && $scope.viewModel.checkbox28 == false && $scope.viewModel.checkbox29 == false && $scope.viewModel.checkbox30 == false && $scope.viewModel.checkbox31 == false){
				$("#salary-table thead tr th:eq(4)").hide();
			}else{
				$("#salary-table thead tr th:eq(4)").show();
			}
		}
		
		if(type == 24){
			if($scope.viewModel.checkbox24 == true){
				x[4].colSpan = x[4].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox22 == true || $scope.viewModel.checkbox23 == true || $scope.viewModel.checkbox24 == true || $scope.viewModel.checkbox25 == true || $scope.viewModel.checkbox26 == true || $scope.viewModel.checkbox27 == true || $scope.viewModel.checkbox28 == true || $scope.viewModel.checkbox29 == true || $scope.viewModel.checkbox30 == true || $scope.viewModel.checkbox31 == true){
					x[4].colSpan = x[4].colSpan * 1 + 1;
				}else{
					x[4].colSpan = x[4].colSpan;
					$("#salary-table thead tr th:eq(4)").show();
				}
			}
			$scope.viewModel.checkbox24 = !$scope.viewModel.checkbox24;
			if($scope.viewModel.checkbox22 == false && $scope.viewModel.checkbox23 == false && $scope.viewModel.checkbox24 == false && $scope.viewModel.checkbox25== false && $scope.viewModel.checkbox26 == false && $scope.viewModel.checkbox27 == false && $scope.viewModel.checkbox28 == false && $scope.viewModel.checkbox29 == false && $scope.viewModel.checkbox30 == false && $scope.viewModel.checkbox31 == false){
				$("#salary-table thead tr th:eq(4)").hide();
			}else{
				$("#salary-table thead tr th:eq(4)").show();
			}
		}
		
		if(type == 25){
			if($scope.viewModel.checkbox25 == true){
				x[4].colSpan = x[4].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox22 == true || $scope.viewModel.checkbox23 == true || $scope.viewModel.checkbox24 == true || $scope.viewModel.checkbox25 == true || $scope.viewModel.checkbox26 == true || $scope.viewModel.checkbox27 == true || $scope.viewModel.checkbox28 == true || $scope.viewModel.checkbox29 == true || $scope.viewModel.checkbox30 == true || $scope.viewModel.checkbox31 == true){
					x[4].colSpan = x[4].colSpan * 1 + 1;
				}else{
					x[4].colSpan = x[4].colSpan;
					$("#salary-table thead tr th:eq(4)").show();
				}
			}
			$scope.viewModel.checkbox25 = !$scope.viewModel.checkbox25;
			if($scope.viewModel.checkbox22 == false && $scope.viewModel.checkbox23 == false && $scope.viewModel.checkbox24 == false && $scope.viewModel.checkbox25== false && $scope.viewModel.checkbox26 == false && $scope.viewModel.checkbox27 == false && $scope.viewModel.checkbox28 == false && $scope.viewModel.checkbox29 == false && $scope.viewModel.checkbox30 == false && $scope.viewModel.checkbox31 == false){
				$("#salary-table thead tr th:eq(4)").hide();
			}else{
				$("#salary-table thead tr th:eq(4)").show();
			}
		}
		
		if(type == 26){
			if($scope.viewModel.checkbox26 == true){
				x[4].colSpan = x[4].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox22 == true || $scope.viewModel.checkbox23 == true || $scope.viewModel.checkbox24 == true || $scope.viewModel.checkbox25 == true || $scope.viewModel.checkbox26 == true || $scope.viewModel.checkbox27 == true || $scope.viewModel.checkbox28 == true || $scope.viewModel.checkbox29 == true || $scope.viewModel.checkbox30 == true || $scope.viewModel.checkbox31 == true){
					x[4].colSpan = x[4].colSpan * 1 + 1;
				}else{
					x[4].colSpan = x[4].colSpan;
					$("#salary-table thead tr th:eq(4)").show();
				}
			}
			$scope.viewModel.checkbox26 = !$scope.viewModel.checkbox26;
			if($scope.viewModel.checkbox22 == false && $scope.viewModel.checkbox23 == false && $scope.viewModel.checkbox24 == false && $scope.viewModel.checkbox25== false && $scope.viewModel.checkbox26 == false && $scope.viewModel.checkbox27 == false && $scope.viewModel.checkbox28 == false && $scope.viewModel.checkbox29 == false && $scope.viewModel.checkbox30 == false && $scope.viewModel.checkbox31 == false){
				$("#salary-table thead tr th:eq(4)").hide();
			}else{
				$("#salary-table thead tr th:eq(4)").show();
			}
		}
		
		if(type == 27){
			if($scope.viewModel.checkbox27 == true){
				x[4].colSpan = x[4].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox22 == true || $scope.viewModel.checkbox23 == true || $scope.viewModel.checkbox24 == true || $scope.viewModel.checkbox25 == true || $scope.viewModel.checkbox26 == true || $scope.viewModel.checkbox27 == true || $scope.viewModel.checkbox28 == true || $scope.viewModel.checkbox29 == true || $scope.viewModel.checkbox30 == true || $scope.viewModel.checkbox31 == true){
					x[4].colSpan = x[4].colSpan * 1 + 1;
				}else{
					x[4].colSpan = x[4].colSpan;
					$("#salary-table thead tr th:eq(4)").show();
				}
			}
			$scope.viewModel.checkbox27 = !$scope.viewModel.checkbox27;
			if($scope.viewModel.checkbox22 == false && $scope.viewModel.checkbox23 == false && $scope.viewModel.checkbox24 == false && $scope.viewModel.checkbox25== false && $scope.viewModel.checkbox26 == false && $scope.viewModel.checkbox27 == false && $scope.viewModel.checkbox28 == false && $scope.viewModel.checkbox29 == false && $scope.viewModel.checkbox30 == false && $scope.viewModel.checkbox31 == false){
				$("#salary-table thead tr th:eq(4)").hide();
			}else{
				$("#salary-table thead tr th:eq(4)").show();
			}
		}
		
		if(type == 28){
			if($scope.viewModel.checkbox28 == true){
				x[4].colSpan = x[4].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox22 == true || $scope.viewModel.checkbox23 == true || $scope.viewModel.checkbox24 == true || $scope.viewModel.checkbox25 == true || $scope.viewModel.checkbox26 == true || $scope.viewModel.checkbox27 == true || $scope.viewModel.checkbox28 == true || $scope.viewModel.checkbox29 == true || $scope.viewModel.checkbox30 == true || $scope.viewModel.checkbox31 == true){
					x[4].colSpan = x[4].colSpan * 1 + 1;
				}else{
					x[4].colSpan = x[4].colSpan;
					$("#salary-table thead tr th:eq(4)").show();
				}
			}
			$scope.viewModel.checkbox28 = !$scope.viewModel.checkbox28;
			if($scope.viewModel.checkbox22 == false && $scope.viewModel.checkbox23 == false && $scope.viewModel.checkbox24 == false && $scope.viewModel.checkbox25== false && $scope.viewModel.checkbox26 == false && $scope.viewModel.checkbox27 == false && $scope.viewModel.checkbox28 == false && $scope.viewModel.checkbox29 == false && $scope.viewModel.checkbox30 == false && $scope.viewModel.checkbox31 == false){
				$("#salary-table thead tr th:eq(4)").hide();
			}else{
				$("#salary-table thead tr th:eq(4)").show();
			}
		}
		
		if(type == 29){
			if($scope.viewModel.checkbox29 == true){
				x[4].colSpan = x[4].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox22 == true || $scope.viewModel.checkbox23 == true || $scope.viewModel.checkbox24 == true || $scope.viewModel.checkbox25 == true || $scope.viewModel.checkbox26 == true || $scope.viewModel.checkbox27 == true || $scope.viewModel.checkbox28 == true || $scope.viewModel.checkbox29 == true || $scope.viewModel.checkbox30 == true || $scope.viewModel.checkbox31 == true){
					x[4].colSpan = x[4].colSpan * 1 + 1;
				}else{
					x[4].colSpan = x[4].colSpan;
					$("#salary-table thead tr th:eq(4)").show();
				}
			}
			$scope.viewModel.checkbox29 = !$scope.viewModel.checkbox29;
			if($scope.viewModel.checkbox22 == false && $scope.viewModel.checkbox23 == false && $scope.viewModel.checkbox24 == false && $scope.viewModel.checkbox25== false && $scope.viewModel.checkbox26 == false && $scope.viewModel.checkbox27 == false && $scope.viewModel.checkbox28 == false && $scope.viewModel.checkbox29 == false && $scope.viewModel.checkbox30 == false && $scope.viewModel.checkbox31 == false){
				$("#salary-table thead tr th:eq(4)").hide();
			}else{
				$("#salary-table thead tr th:eq(4)").show();
			}
		}
		
		
		if(type == 30){
			if($scope.viewModel.checkbox30 == true){
				x[4].colSpan = x[4].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox22 == true || $scope.viewModel.checkbox23 == true || $scope.viewModel.checkbox24 == true || $scope.viewModel.checkbox25 == true || $scope.viewModel.checkbox26 == true || $scope.viewModel.checkbox27 == true || $scope.viewModel.checkbox28 == true || $scope.viewModel.checkbox29 == true || $scope.viewModel.checkbox30 == true || $scope.viewModel.checkbox31 == true){
					x[4].colSpan = x[4].colSpan * 1 + 1;
				}else{
					x[4].colSpan = x[4].colSpan;
					$("#salary-table thead tr th:eq(4)").show();
				}
			}
			$scope.viewModel.checkbox30 = !$scope.viewModel.checkbox30;
			if($scope.viewModel.checkbox22 == false && $scope.viewModel.checkbox23 == false && $scope.viewModel.checkbox24 == false && $scope.viewModel.checkbox25== false && $scope.viewModel.checkbox26 == false && $scope.viewModel.checkbox27 == false && $scope.viewModel.checkbox28 == false && $scope.viewModel.checkbox29 == false && $scope.viewModel.checkbox30 == false && $scope.viewModel.checkbox31 == false){
				$("#salary-table thead tr th:eq(4)").hide();
			}else{
				$("#salary-table thead tr th:eq(4)").show();
			}
		}
		
		
		if(type == 31){
			if($scope.viewModel.checkbox31 == true){
				x[4].colSpan = x[4].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox22 == true || $scope.viewModel.checkbox23 == true || $scope.viewModel.checkbox24 == true || $scope.viewModel.checkbox25 == true || $scope.viewModel.checkbox26 == true || $scope.viewModel.checkbox27 == true || $scope.viewModel.checkbox28 == true || $scope.viewModel.checkbox29 == true || $scope.viewModel.checkbox30 == true || $scope.viewModel.checkbox31 == true){
					x[4].colSpan = x[4].colSpan * 1 + 1;
				}else{
					x[4].colSpan = x[4].colSpan;
					$("#salary-table thead tr th:eq(4)").show();
				}
			}
			$scope.viewModel.checkbox31 = !$scope.viewModel.checkbox31;
			if($scope.viewModel.checkbox22 == false && $scope.viewModel.checkbox23 == false && $scope.viewModel.checkbox24 == false && $scope.viewModel.checkbox25== false && $scope.viewModel.checkbox26 == false && $scope.viewModel.checkbox27 == false && $scope.viewModel.checkbox28 == false && $scope.viewModel.checkbox29 == false && $scope.viewModel.checkbox30 == false && $scope.viewModel.checkbox31 == false){
				$("#salary-table thead tr th:eq(4)").hide();
			}else{
				$("#salary-table thead tr th:eq(4)").show();
			}
		}
		
		if(type == 32){
			if($scope.viewModel.checkbox32 == true){
				x[6].colSpan = x[6].colSpan - 1;
			}else{
				if($scope.viewModel.checkbox32 == true){
					x[6].colSpan = x[6].colSpan * 1 + 1;
				}else{
					x[6].colSpan = x[6].colSpan;
					$("#salary-table thead tr th:eq(6)").show();
				}
			}
			$scope.viewModel.checkbox32 = !$scope.viewModel.checkbox32;
			if($scope.viewModel.checkbox32 == false){
				$("#salary-table thead tr th:eq(6)").hide();
			}else{
				$("#salary-table thead tr th:eq(6)").show();
			}
		}
	}


        /** ***批量导入**** */
        $scope.viewSalaryImportModel = {};
        $scope.viewSalaryImportModel.attachmentId = null;
        $scope.viewSalaryImportModel.messageHideType = false;
        $scope.viewSalaryImportModel.successHideType = false;
        $scope.viewSalaryImportModel.message = null;
        $scope.viewSalaryImportModel.isArray = false;
        $scope.viewSalaryImportModel.year="";
        $scope.viewSalaryImportModel.month="";
        

        $scope.viewSalaryImportModel.Load = function() {
            $scope.viewSalaryImportModel.show = true;
            $scope.viewSalaryImportModel.year="";
            $scope.viewSalaryImportModel.month="";
        };

        $scope.viewSalaryImportModel.unLoad = function() {
        	$scope.viewSalaryImportModel.show = false;
        };

        $scope.viewSalaryImportModel.getTemplate = function () {
            $rootScope.isLoading = true;
            Service.getTemplateUrl(function (data) {
                $rootScope.isLoading = false;
                window.location.href       = data;
            }, function () {
                $rootScope.isLoading = false;
                //$rootScope.alertError("系统错误!");
                $scope.viewSalaryImportModel.messageHideType=true;
                $scope.viewSalaryImportModel.message="系统错误";
                $scope.viewSalaryImportModel.isArray=false;
            });
        };

        $scope.viewSalaryImportModel.fileUploadComplete    = function (data) {
            $scope.viewSalaryImportModel.messageHideType=false;
            $scope.viewSalaryImportModel.successHideType=false;
            var dataList=data;
            if (dataList[0]['attachment'] != null) {
                $scope.$apply(function () {
                    $scope.viewSalaryImportModel.attachmentId = dataList[0]['attachment']['attachmentId'];
                    $scope.viewSalaryImportModel.setfileUpload();
                });
            }
        };
        
        //调用读取文件中的年月时间
        $scope.viewSalaryImportModel.setfileUpload=function(){
        	//接口返回 年月等信息
        	/*var params =  {
        			attachmentId: $scope.viewSalaryImportModel.attachmentId
        		};*/
        	/*Service.getSalaryImportYearMonth(params,function (data) {
                $scope.viewSalaryImportModel.year=data.salaryYear;
                $scope.viewSalaryImportModel.month=data.salaryMonth;
            }, function () {
                $rootScope.isLoading = false;
                //$rootScope.alertError("系统错误!");
                $scope.viewSalaryImportModel.messageHideType=true;
                $scope.viewSalaryImportModel.message="系统错误";
                $scope.viewSalaryImportModel.isArray=false;
            });*/
        	$scope.viewSalaryImportModel.save();
        };

        //保持信息
        $scope.viewSalaryImportModel.save = function () {
            var str="确认是否导入工资报表！";
            $rootScope.alertConfirm(str,
                function() {
                    if ($scope.viewSalaryImportModel.attachmentId != null) {
                        $rootScope.isLoading = true;
                        Service.saveSalaryListExcel({
                            attachmentId: $scope.viewSalaryImportModel.attachmentId/*
                            salaryYear: $scope.viewSalaryImportModel.year,
                            salaryMonth:  $scope.viewSalaryImportModel.month*/
                        }, function (data) {
                            $rootScope.isLoading = false;
                            $rootScope.alertInfo("工资报表导入成功");
                            $scope.viewSalaryImportModel.unLoad();
                            $scope.viewModel.bindHistoryData();
                        }, function (data) {
                            if (angular.isArray(data['fault'])) {
                                var faultMessage = [data['fault'][0]['message']].concat(data['fault'][0]['errorData']);
                                $rootScope.alertError(faultMessage);
                            } else {
                                $scope.viewSalaryImportModel.message=data['fault']['message'];
                                $rootScope.alertError(data['fault']['message']);
                            }
                            $rootScope.isLoading = false;
                        });
                    } else {
                        $rootScope.alertError("请先上传文件!");
                    }
                });
        };
} ]);